#include<iostream>
#include <sys/types.h>
#include<sys/stat.h>
#include <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <errno.h>
#include <unistd.h>

//读命名管道，写入目标文件
int main()
{
    int outfd = open("ret.txt",O_WRONLY|O_CREAT|O_TRUNC,0644);
    if(outfd == -1)
    {
        perror("open");
        return 1;
    }

    int infd = open("fifo",O_RDONLY);
    if(infd == -1)
    {
        perror("open");
        return 2;
    }

    char buf[1024];
    int n;
    while((n = read(infd,buf,sizeof(buf))) > 0)
    {
        write(outfd,buf,n);
    }

    close(infd);
    close(outfd);
    unlink("fifo");

    return 0;
}